home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Trial / Paint Shop Pro XI / Data1.cab / _D1151E09D9FD44ED8F14F9FD02509456 < prev    next >
Encoding:
Text File  |  2006-08-04  |  5.4 KB  |  119 lines

  1. from PSPApp import *
  2. import PSPUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': 'Linda Nieuwenstein',
  7.         'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All rights reserved.',
  8.         'Description': "Split the current image to CMYK, putting the separate channels back as layers in a layer group.",
  9.         'Host': 'Paint Shop Pro',
  10.         'Host Version': '8.00'
  11.         }
  12.  
  13.  
  14. def Do(Environment):
  15.     if PSPUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.     
  18.     # keep track of the doc we are starting with
  19.     TargetDoc = App.TargetDocument
  20.     
  21.     # start by splitting the current image.
  22.     App.Do( Environment, 'SplitToCMYK', {
  23.             'GeneralSettings': {
  24.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  25.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  26.                 }
  27.             })
  28.  
  29.     # the split created 4 new documents and puts them at the end of the open list.
  30.     # make a four element list that we can reorder.  At this point we don't
  31.     # care about the contents, just that it has four elements
  32.     NewDocs = App.Documents[-4:]                # grab the last four docs
  33.           
  34.     # now loop over the four newest docs.
  35.     for ChannelDoc in App.Documents[-4:]:
  36.         Name = ChannelDoc.Title
  37.         if Name.find( PSPUtils.Black ) != -1:
  38.           NewDocs[0] = ChannelDoc # make Black first
  39.         elif Name.find( PSPUtils.Yellow ) != -1:
  40.           NewDocs[1] = ChannelDoc # make Yellow next
  41.         elif Name.find( PSPUtils.Magenta ) != -1:
  42.           NewDocs[2] = ChannelDoc # then Magenta
  43.         elif Name.find( PSPUtils.Cyan ) != -1:
  44.           NewDocs[3] = ChannelDoc # make Cyan last
  45.     
  46.     FirstChannel = App.Constants.Boolean.true   # need special handling on the first one
  47.     
  48.     # We use explicit specification of which document to work on by adding a fourth
  49.     # parameter to the App.Do call.  For operations on one of the single channel
  50.     # images we use one of the saved docs.  For operations on the original doc we use
  51.     # the saved TargetDoc.
  52.     for Doc in NewDocs:  
  53.         # this shouldn't be necessary, but at the moment paste as new layer has a bug,
  54.         # so we promote manually.  This assumes the original image is RGB.
  55.         App.Do( Environment, 'IncreaseColorsTo16Million', {}, Doc )
  56.         
  57.         # copy it to the clipboard        
  58.         App.Do( Environment, 'Copy', {}, Doc  )
  59.         
  60.         # paste it into the existing document - note the specification of target doc
  61.         App.Do( Environment, 'PasteAsNewLayer', {}, TargetDoc )
  62.  
  63.         # when we pasted it the layer came in as Raster Layer n, and we want to know what
  64.         # channel it represents, so pick up the image title and use that to determine
  65.         # the layer name.  Out of split to CMYK the image will be named CyanN, YellowN, MagentaN, and BlackN.
  66.         NewLayerName = Doc.Title
  67.         if NewLayerName.find( PSPUtils.Black ) != -1:
  68.             NewLayerName = PSPUtils.BlackChannel
  69.         elif NewLayerName.find( PSPUtils.Yellow ) != -1:
  70.             NewLayerName = PSPUtils.YellowChannel
  71.         elif NewLayerName.find( PSPUtils.Magenta ) != -1:
  72.             NewLayerName = PSPUtils.MagentaChannel
  73.         else:
  74.             NewLayerName = PSPUtils.CyanChannel
  75.             
  76.         # now that we have the layer name, rename it
  77.         App.Do( Environment, 'LayerProperties', {
  78.                 'General': {
  79.                     'Name': NewLayerName, 
  80.                     }, 
  81.                 'GeneralSettings': {
  82.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  83.                     'AutoActionMode': App.Constants.AutoActionMode.Default
  84.                     }
  85.                 }, TargetDoc )
  86.         
  87.         # we want the channels to end up inside of a layer group, so after we
  88.         # paste the first channel in create a layer group to hold it, and then select
  89.         # the layer inside the group so subsequent creates go where we want them.
  90.         if FirstChannel == App.Constants.Boolean.true:
  91.             FirstChannel = App.Constants.Boolean.false
  92.  
  93.             # create the layer group
  94.             App.Do( Environment, 'NewLayerGroup', {
  95.                     'General': {
  96.                         'Name': PSPUtils.CMYKChannels, 
  97.                         }, 
  98.                     'GeneralSettings': {
  99.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  100.                         'AutoActionMode': App.Constants.AutoActionMode.Match
  101.                         }
  102.                     }, TargetDoc )
  103.  
  104.             # select the member of the group rather than the group itself            
  105.             NewLayer = App.Do( Environment, 'SelectLayer', {
  106.                     'Path': (0,0,[1],App.Constants.Boolean.false), 
  107.                     'GeneralSettings': {
  108.                         'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  109.                         'AutoActionMode': App.Constants.AutoActionMode.Default
  110.                         }
  111.                     }, TargetDoc)
  112.             
  113.         # do the close in silent mode since we don't want to save changes                
  114.         App.Do( Environment, 'FileClose', {
  115.                 'GeneralSettings': {
  116.                     'ExecutionMode': App.Constants.ExecutionMode.Silent, 
  117.                     'AutoActionMode': App.Constants.AutoActionMode.Match
  118.                     }
  119.                 }, Doc )